<template>
  <div class="my-videos">
    <div class="my-videos-main">
      <ul class="my-videos-ul clearfix">
        <li class="my-videos-item" v-for="item in videos" :key="item.vid">
          <mv-list v-if="item.type == 0" :item="item"></mv-list>
          <video-list
            v-if="item.type == 1"
            :item="item"
            :showTime="false"
          ></video-list>
        </li>
      </ul>
    </div>
    <div class="videos-el-pagination" v-if="vTotal > 30">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="30"
        layout="prev, pager, next, jumper"
        :total="vTotal"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import MvList from "components/mvlist/MvList.vue";
import VideoList from "components/videolist/VideoList.vue";
export default {
  components: {
    MvList,
    VideoList,
  },
  props: {
    vTotal: {
      type: Number,
      default() {
        return 0;
      },
    },
  },
  data() {
    return {
      videos: [],
      currentPage: 1,
    };
  },
  mounted() {
    this.getVideos();
  },
  methods: {
    handleCurrentChange() {
      this.getVideos();
      // 点击分页后，滚动到评论的头部，141为页面头部组件的高度
      this.$emit("pScroll", 0);
    },
    getVideos() {
      this.axios({
        url: "/mv/sublist?limit=30&offset=" + (this.currentPage - 1) * 30,
      })
        .then((res) => {
          this.videos = res.data.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style>
.my-videos {
  padding: 0 10px;
}
.my-videos-ul {
  margin-right: -20px;
}
.my-videos-item {
  float: left;
  width: 25%;
}
.video-el-pagination {
  position: relative;
  text-align: center;
  margin: 20px auto;
}
</style>